﻿using System;
using System.Configuration;
using System.Data.Linq;
using System.Linq;
using Controllers;

namespace Web
{
    public partial class VacationLogout : System.Web.UI.Page
    {
        protected ReqVacationMain reqVacationMain;
        protected string empName;
        protected void Page_Load(object sender, EventArgs e)
        {
            string formNo = Request.QueryString["formNo"];
            ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
            DataLoadOptions dlo = new DataLoadOptions();
            dlo.LoadWith<ReqVacationMain>(r => r.ReqVacationSubs);
            ctx.LoadOptions = dlo;
            reqVacationMain = ctx.ReqVacationMains.Single(r => r.FormNo == formNo);

            rptList.DataSource = reqVacationMain.ReqVacationSubs;
            rptList.DataBind();
            Employee employee = ctx.Employees.Single(r => r.Id == reqVacationMain.EmpId);
            empName = employee.Name;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
            string formNo = Request.QueryString["formNo"];
            ReqVacationMain reqVacationMain = ctx.ReqVacationMains.Single(r => r.FormNo == formNo);
            reqVacationMain.RealStartTime = DateTime.Parse(RealStartTime.Value);
            reqVacationMain.RealEndTime = DateTime.Parse(RealEndTime.Value);
            reqVacationMain.Remarks = Remarks.Value;
            reqVacationMain.StatusId = 5;
            ctx.SubmitChanges();
            Response.Write("<script>window.returnValue='Success';window.close();</script>");
        }
    }
}